package net.lzzy.practices;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author  Jaymo on 2022/5/15
 * Decription:
 */
@Component
public class PracticesConfigurer implements WebMvcConfigurer {
    @Value("${user.pic}")
    private String imgPath;
    @Value("${pic.size}")
    private int maxSize;

    @Bean
    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setMaxUploadSize(maxSize);
        return resolver;
    }

    @Override
    public  void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/rescource/",
                        "classpath:/static/",
                        "file:/+ imgPath");

    }
}
